package transactions;


public class TransactionAction
{
	protected AbstractTransaction transaction;
	protected Object object;
	protected Object beforeState;
	protected Object afterState;
	private TransactionActionType action;
	private TransactionAction(){};

	public AbstractTransaction getTransaction() {
		return transaction;
	}

	public void setTransaction(AbstractTransaction transaction) {
		this.transaction = transaction;
	}

	public Object getObject() {
		return object;
	}

	public void setObject(Object object) {
		this.object = object;
	}

	public Object getBeforeState() {
		return beforeState;
	}

	public void setBeforeState(Object beforeState) {
		this.beforeState = beforeState;
	}

	public Object getAfterState() {
		return afterState;
	}

	public void setAfterState(Object afterState) {
		this.afterState = afterState;
	}

	public TransactionActionType getAction() {
		return action;
	}

	public void setAction(TransactionActionType action) {
		this.action = action;
	}

	public Object redo(){
		//TODO: recall transaction main method
		transaction.execute();
		return afterState;

	}

	public Object undo(){
		//TODO: rollback
		transaction.rollback();
		return beforeState;
	}


	public class UpdateTransactionAction extends TransactionAction
	{
		public UpdateTransactionAction(AbstractTransaction transaction, Object object, Object beforeState, Object afterState) {
			// TODO Auto-generated constructor stub
			setAction(TransactionActionType.UPDATE);
			setTransaction(transaction);
			setAfterState(afterState);
			setBeforeState(beforeState);
		}
	}

	public class InsertTransactionAction extends TransactionAction
	{
		public InsertTransactionAction(AbstractTransaction transaction, Object object, Object afterState) {
			// TODO Auto-generated constructor stub
			setAction(TransactionActionType.UPDATE);
			setTransaction(transaction);
			setAfterState(afterState);
			setBeforeState(null);
		}
		private void setBeforeSate(Object obj){};
	}

	public class DeleteTransactionAction extends TransactionAction
	{
		public DeleteTransactionAction(AbstractTransaction transaction, Object object, Object beforeState) {
			// TODO Auto-generated constructor stub
			setAction(TransactionActionType.UPDATE);
			setTransaction(transaction);
			setAfterState(null);
			setBeforeState(beforeState);
		}

		private void setAfterSate(Object obj){
			
		};
	}
}
